export function isPhone(phone) {
  return /^1(3\d|4\d|5\d|6\d|7\d|8\d|9\d)\d{8}$/g.test(phone);
}

export function check(email) {
  var reg = /^\w+((.\w+)|(-\w+))@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+).[A-Za-z0-9]+$/; //正则表达式
  return reg.test(email);
}

export function requireJS(url) {
  return new Promise((resolve, reject) => {
    let script = document.createElement('script');
    if (script.readyState) { // IE
      script.onreadystatechange = function () {
        if (script.readyState === 'loaded' || script.readyState === 'complete') {
          script.onreadystatechange = null;
          resolve(window.AMap);
        }
      }
    } else { // 其他浏览器
      script.onload = function () {
        resolve(window.AMap);
      }
    }
    script.src = url;
    document.head.appendChild(script);
  });
};

export default {
  isPhone,
  check,
  requireJS
};
